package cn.xfdzx.android.apps.shop.activity;


import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.ruzhu.XFDShopInActivity;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.bean.AgreementBeen;
import cn.xfdzx.android.apps.shop.contract.AgreementContract;
import cn.xfdzx.android.apps.shop.presenter.AgreementPresenter;
import cn.xfdzx.android.apps.shop.util.StatusBarUtil;
import cn.xfdzx.android.apps.shop.util.UtilsData;
import cn.xfdzx.android.apps.shop.view.CustomScrollview;
/**
 * 用户协议页面，隐私协议，商家服务协议
 * */

public class UserAgreementActivity extends BaseMvpActivity<AgreementPresenter> implements AgreementContract.View {

    @BindView(R.id.ll_state)
    LinearLayout llState;
    @BindView(R.id.iv_back)
    ImageView ivBack;      //标题栏-左边按钮
    @BindView(R.id.tv_title)
    TextView tv_title;      //标题
    @BindView(R.id.tv_agreement)
    TextView tvAgreement;

    private RelativeLayout.LayoutParams item_bar;
    private String type = "";

    @Override
    public int getLayoutId() {
        return R.layout.activity_useragreement;
    }

    @Override
    public void initView() {
        initHigh();
        mPresenter = new AgreementPresenter();
        mPresenter.attachView(this);
        type = getIntent().getStringExtra("type");
        if (type.equals("0")) {//用户协议
            tv_title.setText("用户协议");
            mPresenter.userAgreement();
        } else if (type.equals("1")){//隐私协议
            tv_title.setText("隐私协议");
            mPresenter.privacyAgreement();
        }else if (type.equals("2")){//商家服务协议
            tv_title.setText("商家服务协议");
            mPresenter.serviceAgreement();
        }

    }

    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:    //返回按钮点击
                finish();
                break;
        }
    }

    @Override
    public void showLoading() {

    }

    private void initHigh() {
        item_bar = (RelativeLayout.LayoutParams) llState.getLayoutParams();
        item_bar.height = StatusBarUtil.getStatusBarHeight(this);
        llState.setLayoutParams(item_bar);
    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    protected boolean isUseFullScreenMode() {
        return true;
    }

    @Override
    public void onAgreementSuccess(AgreementBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            tvAgreement.setText(Html.fromHtml(bean.getData()));

        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.detachView();
    }
}
